// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   type_change_ok.java

package oa.config.press;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class type_change_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;
	nseer_db_backup1 erp_db;

	public type_change_ok()
	{
		erp_db = null;
	}

	public synchronized void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			java.io.PrintWriter out = response.getWriter();
			nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			if (oa_db.conn((String)dbSession.getAttribute("unit_db_name")) && hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String register_ID = (String)session.getAttribute("human_IDD");
				String id = request.getParameter("id");
				String describe1 = request.getParameter("describe1");
				String responsible_person = "";
				int m = 0;
				for (StringTokenizer tokenTO7 = new StringTokenizer(describe1, ", "); tokenTO7.hasMoreTokens();)
				{
					String sql1 = (new StringBuilder("insert into oa_config_human_ID_temp(human_ID,register_ID) values('")).append(tokenTO7.nextToken()).append("','").append(register_ID).append("') ").toString();
					oa_db.executeUpdate(sql1);
					m++;
				}

				String sql5 = (new StringBuilder("select distinct human_ID from oa_config_human_ID_temp where register_ID='")).append(register_ID).append("'").toString();
				ResultSet rs5 = oa_db.executeQuery(sql5);
				rs5.last();
				int n = 0;
				if (rs5.getRow() != m)
					n++;
				String sql6 = (new StringBuilder("delete from oa_config_human_ID_temp where register_ID='")).append(register_ID).append("'").toString();
				oa_db.executeUpdate(sql6);
				for (StringTokenizer tokenTO8 = new StringTokenizer(describe1, ", "); tokenTO8.hasMoreTokens();)
				{
					String sql2 = (new StringBuilder("select * from hr_file where human_ID='")).append(tokenTO8.nextToken()).append("'").toString();
					ResultSet rs2 = hr_db.executeQuery(sql2);
					if (rs2.next())
						responsible_person = (new StringBuilder(String.valueOf(responsible_person))).append(rs2.getString("human_name")).append(", ").toString();
					else
						n++;
				}

				for (StringTokenizer tokenTO9 = new StringTokenizer(describe1, ", "); tokenTO9.hasMoreTokens();)
				{
					String sql3 = (new StringBuilder("select * from hr_file where human_ID='")).append(tokenTO9.nextToken()).append("'").toString();
					ResultSet rs3 = hr_db.executeQuery(sql3);
					if (!rs3.next())
						n++;
				}

				if (n != 0)
				{
					response.sendRedirect("oa/config/press/type_change_ok_a.jsp");
				} else
				{
					String sql = (new StringBuilder("update oa_config_public_char set describe1='")).append(describe1).append("',describe2='").append(responsible_person).append("' where id='").append(id).append("'").toString();
					oa_db.executeUpdate(sql);
					response.sendRedirect("oa/config/press/type_change_ok_b.jsp");
				}
				hr_db.commit();
				oa_db.commit();
				hr_db.close();
				oa_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
